﻿Public Class CMSPHERE
    Dim connect As CONDB = CONDB.NewConnection
    Dim s As FILTERCLASS
    Dim PROVIDER_Check As New PROVIDERSCLASS

    Private Sub CLINICTxt_Click(sender As Object, e As EventArgs) Handles CLINICTxt.Click
        CLINICTxt.Text = ""
        CLINICTxt.Tag = ""
    End Sub

    Private Sub CMSPHERE_Load(sender As Object, e As EventArgs) Handles Me.Load
        SelectDatagridComsphere()
        SearchClinicboy()

        DesignForm(Me)
        DesignGrid(COMSPHEREGrid)

        PROVIDER_Check.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub SelectDatagridComsphere()
        Dim objSelectDataCOMSPHERE As New COMSPHERECLASS
        Dim COMSPHERE As DataTable
        COMSPHERE = connect.GetTable(objSelectDataCOMSPHERE.SelectComsphere_)
        COMSPHEREGrid.PrimaryGrid.DataSource = COMSPHERE
    End Sub

    Private Sub cleardata()
        COMIDTxt.Text = ""
        CLINICTxt.Text = ""
        COM_NAMETxt.Text = ""
        comspherestatuscheck.Checked = False
        F_CASHIERChk.Checked = False
    End Sub

    Private Sub COMSPHEREGrid_CellClick_1(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles COMSPHEREGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัส").Value() IsNot DBNull.Value Then
            COMIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัส").Value()
        Else
            COMIDTxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("หน่วยงาน").Value() IsNot DBNull.Value Then
            CLINICTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("หน่วยงาน").Value()
        Else
            CLINICTxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("clinic").Value() IsNot DBNull.Value Then
            CLINICTxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("clinic").Value()
        Else
            CLINICTxt.Tag = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("Computer Name").Value() IsNot DBNull.Value Then
            COM_NAMETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("Computer Name").Value()
        Else
            COM_NAMETxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            comspherestatuscheck.Checked = True
        Else
            comspherestatuscheck.Checked = False
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("F_CASHIER").Value() = True Then
            F_CASHIERChk.Checked = True
        Else
            F_CASHIERChk.Checked = False
        End If
        connect = CONDB.NewConnection()
        If e.GridCell.GridColumn.Name = "สถานะการเปิดใช้งาน" Then
            Try
                Dim Sql As String
                connect.BeginTrans()
                Sql = "UPDATE comsphere SET "
                If Convert.ToBoolean(CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value()) = True Then
                    Sql += "`status` = 1 "
                Else
                    Sql += "`status` = 0 "
                End If
                Sql += "WHERE `comid` = '" & COMIDTxt.Text & "' ;"
                connect.ExecuteNonQuery(Sql)
                connect.CommitTrans()
            Catch ex As Exception
                connect.RollbackTrans()
                MsgBox(ex.ToString)
            End Try
        End If
        addcomsphere.Enabled = False
    End Sub

    Private Sub SearchClinicboy()
        Dim sql As String
        sql = "SELECT `clinic`,`cliniccode`,`clinicname` FROM masclinic WHERE `status` = 1 "
        s = New FILTERCLASS(CLINICTxt, sql, "รหัสคลินิก,ชื่่อย่อหน่วยงาน,ชื่อหน่วยงาน", "80,85,108", "0,1,1", "0,1,1")
        s.SetTagIndex = 0 ' settag
        s.SetTextIndex = 1 'settext
        s.SetShowBorder = True
    End Sub

    Private Sub addcomsphere_Click_1(sender As Object, e As EventArgs) Handles addcomsphere.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PADD_ = True Then
                If COM_NAMETxt.Text.ToString.Length > 0 And CLINICTxt.Text.ToString.Length > 0 Then
                    Dim objInsertData As New COMSPHERECLASS
                    If Convert.ToString(CLINICTxt.Tag) <> "" Then
                        objInsertData.CLINIC_ = Convert.ToString(CLINICTxt.Tag)
                    End If
                    objInsertData.COM_NAME_ = COM_NAMETxt.Text
                    objInsertData.STATUS_ = comspherestatuscheck.Checked
                    objInsertData.F_CASHIER_ = F_CASHIERChk.Checked
                    objInsertData.insertcomsphereData()

                    SelectDatagridComsphere()

                    cleardata()
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน", MsgBoxStyle.Critical)
                End If
            Else
                MsgBox(PROVIDER_Check.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editcomsphere_Click_1(sender As Object, e As EventArgs) Handles editcomsphere.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                If COMIDTxt.Text.ToString.Length > 0 Then
                    Dim editStat As Integer
                    editStat = MsgBox("ท่านต้องการแก้ไขข้อมูลส่วนดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)
                    If editStat = 1 Then
                        Dim objeditData As New COMSPHERECLASS
                        objeditData.COMID_ = COMIDTxt.Text
                        objeditData.COM_NAME_ = COM_NAMETxt.Text
                        If Convert.ToString(CLINICTxt.Tag) <> "" Then
                            objeditData.CLINIC_ = Convert.ToString(CLINICTxt.Tag)
                        End If
                        objeditData.STATUS_ = comspherestatuscheck.Checked
                        objeditData.F_CASHIER_ = F_CASHIERChk.Checked
                        objeditData.editcomspheredata()

                        SelectDatagridComsphere()

                        cleardata()
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน", MsgBoxStyle.Critical)
                End If
                addcomsphere.Enabled = True
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL("comsphere")
        nextform.ShowDialog()
    End Sub

    Private Sub exportExcel_Click(sender As Object, e As EventArgs) Handles exportExcel.Click
        Dim nextform As New IMPORTEXCEL("comsphere")
        nextform.ShowDialog()
    End Sub


End Class